MySQL Iterate method REPEAT
The difference with WHILE
is that it execute statement before checking the condition. As a result, it iterates one more time than WHILE
does.
CREATE PROCEDURE example2() label1:BEGIN DECLARE rowCount INT DEFAULT 0; DECLARE i INT DEFAULT 0; SELECT COUNT(*) INTO rowCount FROM my_table; REPEAT SELECT i; SET i = i+1000; UNTIL i > rowCount END REPEAT; END; |